package com.jimmy.medical.controller;

import com.jimmy.medical.entity.*;
import com.jimmy.medical.enums.ServiceFlowEnum;
import com.jimmy.medical.enums.SignStatusEnum;
import com.jimmy.medical.service.*;
import com.jimmy.medical.util.AjaxUtils;
import com.jimmy.medical.util.Func_T;
import com.jimmy.medical.model.AjaxResult;
import org.apache.commons.collections.IteratorUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/system")
public class SystemController {
    @Autowired
    private ISystemService systemService;
    @Autowired
    @Qualifier("flowOrderService")
    private IFlowOrderService flowOrderService;

    @RequestMapping("/cityList")
    @ResponseBody
    public AjaxResult<List<SysCode>> cityList() {
        return AjaxUtils.process(new Func_T<List<SysCode>>() {
            @Override
            public List<SysCode> invoke() throws Exception {
                List<SysCode> cityList= systemService.getCityList();
                return cityList;
            }
        });
    }

    @RequestMapping("/serviceTypeList")
    @ResponseBody
    public AjaxResult<List<SysCode>> serviceTypeList() {
        return AjaxUtils.process(new Func_T<List<SysCode>>() {
            @Override
            public List<SysCode> invoke() throws Exception {
                return systemService.getServiceTypeList();
            }
        });
    }

    @RequestMapping("/memberTypeList")
    @ResponseBody
    public AjaxResult<List<MemberType>> memberTypeList(final Long serviceTypeId) {
        return AjaxUtils.process(new Func_T<List<MemberType>>() {
            @Override
            public List<MemberType> invoke() throws Exception {
                return systemService.getMemberTypeList(serviceTypeId);
            }
        });
    }

    @RequestMapping("/serviceFlowMap")
    @ResponseBody
    public AjaxResult<Map<Integer, String>> serviceFlowMap() {
        return AjaxUtils.process(new Func_T<Map<Integer, String>>() {
            @Override
            public Map<Integer, String> invoke() throws Exception {
                return ServiceFlowEnum.getMapValue();
            }
        });
    }

    @RequestMapping("/serviceItemList")
    @ResponseBody
    public AjaxResult<List<ServiceItem>> serviceItemList(final String serviceFlow) {
        return AjaxUtils.process(new Func_T<List<ServiceItem>>() {
            @Override
            public List<ServiceItem> invoke() throws Exception {
                return systemService.getServiceItemList(serviceFlow);
            }
        });
    }

    @RequestMapping("/signStatusMap")
    @ResponseBody
    public AjaxResult<Map<Integer, String>> signStatusMap() {
        return AjaxUtils.process(new Func_T<Map<Integer, String>>() {
            @Override
            public Map<Integer, String> invoke() throws Exception {
                return SignStatusEnum.getMapValue();
            }
        });
    }

    @RequestMapping(value = "/hospitalList")
    @ResponseBody
    public AjaxResult<List<Hospital>> hospitalList(final Long cityId) {
        return AjaxUtils.process(new Func_T<List<Hospital>>() {
            @Override
            public List<Hospital> invoke() throws Exception {
                return systemService.getAllHospitalList(cityId);
            }
        });
    }

    @RequestMapping("/departmentList")
    @ResponseBody
    public AjaxResult<List<HospitalDepartment>> departmentList(final Long hospitalId) {
        return AjaxUtils.process(new Func_T<List<HospitalDepartment>>() {
            @Override
            public List<HospitalDepartment> invoke() throws Exception {
                return systemService.getDepartments(hospitalId);
            }
        });
    }

    @RequestMapping("/doctorList")
    @ResponseBody
    public AjaxResult<List<Doctor>> doctorList(final Long departmentId) {
        return AjaxUtils.process(new Func_T<List<Doctor>>() {
            @Override
            public List<Doctor> invoke() throws Exception {
                return systemService.getDoctors(departmentId);
            }
        });
    }

    /**
     * 指标类型
     *
     * @return
     */
    @RequestMapping("/measureTypeList")
    @ResponseBody
    public AjaxResult<List<SysCode>> measureTypeList() {
        return AjaxUtils.process(new Func_T<List<SysCode>>() {
            @Override
            public List<SysCode> invoke() throws Exception {
                return systemService.getMeasureTypeList();
            }
        });
    }

    /**
     * 所有指标
     *
     * @return
     */
    @RequestMapping("/measureList")
    @ResponseBody
    public AjaxResult<List<Measures>> measureList() {
        return AjaxUtils.process(new Func_T<List<Measures>>() {
            @Override
            public List<Measures> invoke() throws Exception {
                return systemService.getAllMeasureList();
            }
        });
    }
    /**
     * 所有体检指标
     *
     * @return
     */
    @RequestMapping("/physicalMeasureList")
    @ResponseBody
    public AjaxResult<List<Measures>> physicalMeasureList() {
        return AjaxUtils.process(new Func_T<List<Measures>>() {
            @Override
            public List<Measures> invoke() throws Exception {
                return systemService.getAllPhysicalMeasureList();
            }
        });
    }


    /**
     * 指标查询
     *
     * @return
     */
    @RequestMapping("/measureListByFirstLetter")
    @ResponseBody
    public AjaxResult<List<Measures>> measureListByFirstLetter(final String firstLetter) {
        return AjaxUtils.process(new Func_T<List<Measures>>() {
            @Override
            public List<Measures> invoke() throws Exception {
                return systemService.getMeasureList(firstLetter);
            }
        });
    }

    /**
     * 药品查询
     *
     * @return
     */
    @RequestMapping("/medicineListByFirstLetter")
    @ResponseBody
    public AjaxResult<List<Medicines>> medicineListByFirstLetter(final String firstLetter) {
        return AjaxUtils.process(new Func_T<List<Medicines>>() {
            @Override
            public List<Medicines> invoke() throws Exception {
                return systemService.getMedicineList(firstLetter);
            }
        });
    }

    /**
     * 疾病查询
     *
     * @return
     */
    @RequestMapping("/diseaseListByFirstLetter")
    @ResponseBody
    public AjaxResult<List<DiseaseDic>> diseaseListByFirstLetter(final String firstLetter) {
        return AjaxUtils.process(new Func_T<List<DiseaseDic>>() {
            @Override
            public List<DiseaseDic> invoke() throws Exception {
                return systemService.getDiseaseList(firstLetter);
            }
        });
    }

    @RequestMapping("/flowOrderTypeList")
    @ResponseBody
    public AjaxResult<List<FlowOrderType>> flowOrderTypeList() {
        return AjaxUtils.process(new Func_T<List<FlowOrderType>>() {
            @Override
            public List<FlowOrderType> invoke() throws Exception {
                return flowOrderService.flowOrderTypeList();
            }
        });
    }
}
